import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/add_mains_electricity_price/views/effective_data_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';

class ChargeStagePriceWidget extends StatelessWidget {
  final BuildContext context;
  final String title;
  final String startTime;
  final String endTime;
  final String priceString;
  final String servicePriceString;
  final bool isDelete;
  final Function(String startDateTime, String endDateTime) timeChooseCallBack;
  final Function() btnClickCallBack;
  final Function(String str) priceChangeCallBack;
  final Function(String str) serviceChangeCallBack;

  const ChargeStagePriceWidget(
      this.context,
      this.title,
      this.startTime,
      this.endTime,
      this.priceString,
      this.servicePriceString,
      this.timeChooseCallBack,
      this.btnClickCallBack,
      this.priceChangeCallBack,
      this.serviceChangeCallBack,
      {this.isDelete = false,
      Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    GetStorage storage = GetStorage();
    String unit = storage.read('monetaryUnitName')??'元';
    if(unit == '元' || unit == '¥'){
      unit = ResKey.yuan.tr;
    }
    TextEditingController textFieldController = TextEditingController();
    textFieldController.text = priceString;
    TextEditingController serviceTextFieldController = TextEditingController();
    serviceTextFieldController.text = servicePriceString;
    return SizedBox(
      height: 145,
      child: Column(
        children: [
          Gaps.vGap5,
          EffectiveDataWidget(
            context,
            title,
            startTime,
            endTime,
            (startDateTime, endDateTime) {
              timeChooseCallBack(startDateTime, endDateTime);
            },
            () {
              btnClickCallBack();
            },
            isShowHour: true,
            isDelete: isDelete,
            isEdit: true,
          ),
          Container(
            child: Row(
              children: [
                Gaps.hGap16,
                Container(
                    width: 90.w,
                    child: Text(
                      ResKey.siteSettingElectricityElectrovalency.tr,
                      style: ytTextStyle(
                          fontWeight: FontWeight.normal,
                          color: Colour.otherTextColor,
                          fontSize: 14),
                    )),
                // Gaps.hGap10,
                Container(
                  decoration: const BoxDecoration(
                      color: Colour.backgroundColor,
                      borderRadius: BorderRadius.all(Radius.circular(4))),
                  height: 32,
                  width: 106.w,
                  alignment: Alignment.center,
                  child: TextField(
                    textAlign: TextAlign.center,
                    style: const TextStyle(
                        fontSize: 14, color: Colour.mainTextColor),
                    controller: textFieldController,
                    keyboardType:
                        const TextInputType.numberWithOptions(decimal: true),
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      contentPadding: const EdgeInsets.only(bottom: 12),
                      hintText: ResKey.siteSettingElectricityElectrovalency.tr,
                      enabled: true,
                      hintStyle: const TextStyle(
                          fontSize: 14.0,
                          color: Colour.lightTextColor,
                          fontWeight: FontWeight.normal),
                    ),
                    onChanged: (String str) {
                      priceChangeCallBack(str);
                    },
                  ),
                ),
                Gaps.hGap10,
                Container(
                  padding: EdgeInsets.only(left: 4.w),
                  // width: 169.w,
                  child: Text(
                    '$unit/kWh',
                    style: ytTextStyle(
                        fontWeight: FontWeight.normal, fontSize: 14),
                  ),
                )
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 10),
            child: Row(
              children: [
                Gaps.hGap16,
                Container(
                    width: 90.w,
                    child: Text(
                      ResKey.siteSettingElectricityServiceCharge.tr,
                      style: ytTextStyle(
                          fontWeight: FontWeight.normal,
                          color: Colour.otherTextColor,
                          fontSize: 14),
                    )),
                // Gaps.hGap10,
                Container(
                  decoration: const BoxDecoration(
                      color: Colour.backgroundColor,
                      borderRadius: BorderRadius.all(Radius.circular(4))),
                  height: 32,
                  width: 106.w,
                  alignment: Alignment.center,
                  child: TextField(
                    textAlign: TextAlign.center,
                    style: const TextStyle(
                        fontSize: 14, color: Colour.mainTextColor),
                    controller: serviceTextFieldController,
                    keyboardType:
                        const TextInputType.numberWithOptions(decimal: true),
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      contentPadding: const EdgeInsets.only(bottom: 12),
                      hintText: ResKey.siteSettingElectricityElectrovalency.tr,
                      enabled: true,
                      hintStyle: const TextStyle(
                          fontSize: 14.0,
                          color: Colour.lightTextColor,
                          fontWeight: FontWeight.normal),
                    ),
                    onChanged: (String str) {
                      serviceChangeCallBack(str);
                    },
                  ),
                ),
                Gaps.hGap10,
                Container(
                  padding: EdgeInsets.only(left: 4.w),
                  // width: 169.w,
                  child: Text(
                    '$unit/kWh',
                    style: ytTextStyle(
                        fontWeight: FontWeight.normal, fontSize: 14),
                  ),
                )
              ],
            ),
          ),
          Spacer(),
          // Container(
          //   height: 1,
          //   // margin: EdgeInsets.only(left: 16.w, right: 16.w),
          //   color: Colour.dividerColor,
          // ),
        ],
      ),
    );
  }
}
